/**
 * 
 */
package com.patternity.depend;

/**
 * Represents the verdict of a rule for a given dependency situation.
 * 
 * @author cyrille
 */
public enum Verdict {

	ERROR(true, -100), VOTE_MINUS_100(false, -100), VOTE_MINUS_90(false, -90), NEUTRAL(
			false, 0), VOTE_PLUS_100(false, +100), OK_FOR_SURE(true, 100);

	private final boolean isSuperlative;
	private final int rank;

	private Verdict(final boolean isSuperlative, final int rank) {
		this.isSuperlative = isSuperlative;
		this.rank = rank;
	}

	public boolean isError(final int threshold) {
		return rank <= threshold;
	}

	public Verdict fold(final Verdict other) {
		if (isSuperlative) {
			return this;
		}
		if (other.isSuperlative) {
			return other;
		}
		return compareTo(other) > 0 ? this : other;
	}
}
